import feedparser
# https://feedparser.readthedocs.io/en/latest/


def check_feed(channel_id):
    """Accepts YT channel id and returns dict: channel info (title and url) and new video items (15) (id, link,
    title) """
    url = f"https://www.youtube.com/feeds/videos.xml?channel_id={channel_id}"
    feed = feedparser.parse(url)
    list_of_videos = []

    try:
        channel_info = {"channel_title": feed["channel"]["title"], "channel_id": channel_id}
        for entry in feed.entries:
            list_of_videos.append({
                "id": entry["yt_videoid"],
                "link": entry["link"],
                "title": entry["title"]
            })
    except KeyError:
        channel_info = {"channel_title": f"There is no YT channel with ID {channel_id}"}

    return {"info": channel_info, "videos": list_of_videos}
